package com.wc.算法提高课.D第四章_高级数据结构.可持久化数据结构.最大异或和;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/18 12:05
 * @description https://www.acwing.com/problem/content/258/
 */
public class Main {
    /**
     * ans = max(s[p - 1] ^ s[n] ^ x), find p let the ans max
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    // 2 ^ 24 > 1e7
    static int N = 600010, M = N * 24;
    static int[][] tr = new int[M][2];
    static int[] maxId = new int[M];
    // version
    static int[] root = new int[N];
    static int[] s = new int[N];
    static int n, m, idx = 1;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        // when p is zero, is not exist
        // we have version zero
        maxId[0] = -1;
        root[0] = idx++;
        insert(0, 23, 0, root[0]);
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            s[i] = s[i - 1] ^ x;
            root[i] = idx++;
            insert(i, 23, root[i - 1], root[i]);
        }
        int l, r, x;
        while (m-- > 0) {
            String op = sc.next();
            if (op.equals("A")) {
                x = sc.nextInt();
                n++;
                s[n] = s[n - 1] ^ x;
                root[n] = idx++;
                insert(n, 23, root[n - 1], root[n]);
            } else {
                l = sc.nextInt();
                r = sc.nextInt();
                x = sc.nextInt();
                out.println(query(root[r - 1], s[n] ^ x, l - 1));
            }
        }
        out.flush();
    }

    /**
     * @param i version
     * @param k num pos
     * @param p pre_version_tree
     * @param q now_version_tree
     */
    static void insert(int i, int k, int p, int q) {
        if (k < 0) {
            maxId[q] = i;
            return;
        }
        int v = s[i] >> k & 1;
        if (p > 0) tr[q][v ^ 1] = tr[p][v ^ 1];
        tr[q][v] = idx++;
        insert(i, k - 1, tr[p][v], tr[q][v]);
        maxId[q] = Math.max(maxId[tr[q][0]], maxId[tr[q][1]]);
    }

    static int query(int root, int C, int L) {
        int p = root;
        for (int i = 23; i >= 0; i--) {
            int v = C >> i & 1;
            if (maxId[tr[p][v ^ 1]] >= L) p = tr[p][v ^ 1];
            else p = tr[p][v];
        }

        return C ^ s[maxId[p]];
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
